Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing Extensions and Drivers /
Chapter 5 - Printing Functions for Message Overrides / Using the Printing Functions


Interfacing With the Chooser

When the user selects your driver in the Chooser, the Chooser sends certain Chooser messages to you by calling the Device function, which is the interface for the package ('PACK') resource. You need to provide a version of this function to provide Chooser support for your driver. The package resource and its use are described in Inside Macintosh: More Macintosh Toolbox.

QuickDraw GX provides the GXHandleChooserMessage function, which takes care of most of the work of handling the Chooser package code for you. What you need to do is create a Device function, take appropriate action for messages that you need to handle, and pass the parameters on to the GXHandleChooserMessage function. Listing 5-3 shows the ImageWriter II printer driver implementation of the Device function.

Listing 5-3 The Device function for the ImageWriter II printer driver

pascal OSErr Device(short message, short caller,
                   StringPtr objName, StringPtr zoneName,
                   ListHandle theList, long p2)
{
   
   OSErr          anErr = noErr;
   extern Str31   gDriverName;
   StringPtr      pDriverName = &gDriverName;
   extern gxJob   gJob;
   gxJob          *pJob = &gJob;
   
   /* start up QuickDraw GX to begin with */
   if (message == initializeMsg)
      {
      FCBPBRec    pb;

      /* determine the driver name */
      pb.ioCompletion = nil;
      pb.ioNamePtr = pDriverName;
      pb.ioVRefNum = 0;
      pb.ioRefNum = CurResFile();
      pb.ioFCBIndx = 0;
      anErr = PBGetFCBInfo(&pb, false);

      *pJob = nil;
      if (anErr == noErr)
         {
         GXEnterGraphics();
         anErr = GXInitPrinting();
         if (anErr == noErr)
            anErr = GXNewJob(pJob);
         }
      }
      
   /* let the system handle the choosing */
   if (anErr == noErr)
      anErr = GXHandleChooserMessage(*pJob, pDriverName, message,
                        caller, objName, zoneName, theList, p2);
      
   /* shut down QuickDraw GX when done */
   if ( (message == terminateMsg) && (p2 == terminateMsg) )
      {
      if (*pJob != nil)
         GXDisposeJob(*pJob);
      GXExitPrinting();
      GXExitGraphics();
      }

   return(anErr);
   
}
The only Chooser messages that the ImageWriter II printer driver needs to do something special with are initializeMsg and terminateMsg. When the Chooser sends initializeMsg, the ImageWriter II driver initializes QuickDraw GX printing before passing the message along. And when the Chooser sends the terminateMsg message, the ImageWriter II driver terminates QuickDraw GX printing after passing the message along. The Chooser messages are described in Inside Macintosh: Devices.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help